package com.item.yxlottery.yxlottery.callback;

/*
 *------------------------------
 * @创建者      Administrator
 * @创建时间    2016/12/19 14:47
 * @文件描述    stringcallback
 *------------------------------
 */

import android.content.Context;

import com.item.yxlottery.yxlottery.views.StringLoadingDialog;
import com.zhy.http.okhttp.callback.StringCallback;

import okhttp3.Call;
import okhttp3.Request;

public abstract class MyStringCallBack extends StringCallback {

    private Context mContext;
    private boolean mIsShowLoading = false;
    private StringLoadingDialog mLoadingDialog;

    public MyStringCallBack(Context context, boolean isShowLoading) {//isShowLoading:是否显示加载对话框
        mContext = context;
        mIsShowLoading = isShowLoading;
    }

    @Override
    public void onBefore(Request request, int id) {//请求开始
        if (mIsShowLoading) {
            mLoadingDialog = new StringLoadingDialog(mContext);
            mLoadingDialog.setCanceledOnTouchOutside(false);
            mLoadingDialog.show();
        }
        super.onBefore(request, id);
    }

    @Override
    public abstract void onError(Call call, Exception e, int id);//请求失败

    @Override
    public abstract void onResponse(String response, int id);//请求成功

    @Override
    public void onAfter(int id) {//请求完成
        super.onAfter(id);
        if (mLoadingDialog != null) {
            mLoadingDialog.dismiss();
        }
    }
}
